package com.ssy.lingxi.platform.template.service.handler.async;

import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.purchase.api.dto.request.UpdateCreditPointRequest;
import com.ssy.lingxi.purchase.api.feign.PurchaseFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 异步服务 - 采购
 * @author fhj
 * @date 2021/07/09
 * @version 2.0.0
 */
@Slf4j
@Component
public class PurchaseAsyncService {

    @Resource
    private PurchaseFeign purchaseFeign;

    /**
     * 根据会员ID和角色ID更新信用分
     */
    @Async
    public void updateCreditPoint(Long memberId, Long roleId, Integer creditPoint) {
        try {
            //调用采购服务 -> 根据会员ID和角色ID更新信用分
            UpdateCreditPointRequest request = new UpdateCreditPointRequest();
            request.setMemberId(memberId);
            request.setRoleId(roleId);
            request.setCreditPoint(creditPoint);
            Wrapper<?> purchaseWrapper = purchaseFeign.updateCreditPoint(request);
            if(ResponseCode.SUCCESS.getCode() != purchaseWrapper.getCode()) {
                log.error("调用采购服务根据会员ID和角色ID更新信用分接口异常：{}", purchaseWrapper.getMessage());
            }
        } catch (Exception e) {
            log.error("调用采购服务根据会员ID和角色ID更新信用分接口失败：{}", e.getMessage());
        }
    }
}
